home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16664 < prev    next >
Encoding:
Text File  |  1996-08-05  |  971 b   |  50 lines

  1. Path: news.gate.net!rdl-ilps-rxh2
  2. From: rmcinnis@gate.net (Robert B McInnis)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q : pointer to member function
  5. Date: 11 Apr 1996 17:36:24 GMT
  6. Organization: 9th Bit Software
  7. Message-ID: <4kjfuo$2gm@news.gate.net>
  8. References: <4kd9lh$q3q@imag.imag.fr>
  9. NNTP-Posting-Host: miafl3-48.gate.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12.  
  13. For pointers to member functions, refer to Stroustrup v2 pgs. 166, 502.  For a 
  14. quick solution:
  15.  
  16. typedef void (Foo::FooFunc*)() ;
  17.  
  18. class Foo
  19. {
  20.   virtual void calc() ;
  21.   virtual void doit() ;
  22. } ;
  23.  
  24.  
  25. FooFunc  func1, func2 ;
  26. Foo      f1 ;
  27.  
  28. func1 = &Foo::calc ;
  29. func2 = &Foo::doit ;
  30.  
  31. (f1->*func1)() ;  // same as f1->calc()
  32. (f1->*func2)() ;  // same as f1->doit()
  33.  
  34. Hope this helps,
  35.  
  36. Rob
  37.  
  38. ps:  Look for my posts on Observer/Callback for more info/uses on this 
  39. technique.
  40.  
  41. -----------------------------
  42. Robert McInnis
  43. 9th Bit Software
  44. (eMail)  rmcinnis@gate.net
  45. (web  )  http://www.gate.net/~rmcinnis
  46.  
  47.  
  48.  
  49.  
  50.